﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

using System.Xml.Linq;
using Acando.Dynamics.CRM.Silverlight.Library.Helper;

//using Acando.Dynamics.CRM.Silverlight.Library.CrmProxyWcf;
using Acando.Dynamics.CRM.Silverlight.Library.MetaSdk;
using Acando.Dynamics.CRM.Silverlight.Library.Interfaces;

namespace Acando.Dynamics.CRM.Silverlight.Library.Controls
{
    /// <summary>
    /// Interaction logic for SectionControl.xaml
    /// </summary>
    public partial class SectionControl : UserControl
    {
        public SectionControl()
        {
            InitializeComponent();
        }

        public SectionControl(IRecordControl mainControl, EntityMetadata metadata, XElement sectionXml)
            : this()
        {
            this.lblHeader.Text = (from lbl in sectionXml.Elements("labels").Elements("label") 
                                   where lbl.Attribute("languagecode").Value == ApplicationContext.Current.GetUserLanguage().ToString() 
                                   select lbl.Attribute("description").Value).First();

            foreach (var row in sectionXml.Elements("rows").Elements("row"))
            {
                this.listPanel.Children.Add(new RowControl(mainControl,metadata, row));
            }

        }
    }
}
